package com.fingard.dsp.bank.directbank.jrtt01;

import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.fingard.constant.Format;
import com.fingard.dsp.bank.directbank.bankInterface.ITransaction;
import com.fingard.dsp.bank.reqrespobj.transaction.Req7515TodayTrans;
import com.fingard.dsp.bank.reqrespobj.transaction.Req7516HisTrans;
import com.fingard.dsp.bank.reqrespobj.transaction.RetAtsTrans;
import com.fingard.dsp.bank.reqrespobj.transaction.detail.RetAtsTransDetail;
import com.fingard.text.StringHelper;
import com.fingard.util.DateHelper;
import com.fingard.xml.XElement;
import com.fingard.xml.XmlTextReader;
import com.fingard.xml.XmlTextWriter;

/**
 * 财经-海外接口
 */
public class JRTT01Transaction extends JRTT01Base implements ITransaction {

    /**
     * 历史明细
     *
     * @param p_req7516
     * @return
     * @throws Exception
     */
    @Override
    public RetAtsTrans d_7516_HisTrans(Req7516HisTrans p_req7516) throws Exception {
        //增加历史明细支持查询日期
        if (com.fingard.text.StringHelper.hasAnyChar(getBankConfig().getValueAsString("hisTransSupDate"))
                && getBankConfig().getValueAsString("hisTransSupDate").length() == 8) {
            //判断起始日
            Date avaiDate = Format.Date8Format.parse(getBankConfig().getValueAsString("hisTransSupDate"));
            Date startDate = Format.Date8Format.parse(p_req7516.dateFrom);
            Date endDate = Format.Date8Format.parse(p_req7516.dateTo);
            if (endDate.after(avaiDate)) {
                if (startDate.before(avaiDate)) {
                    p_req7516.dateFrom = getBankConfig().getValueAsString("hisTransSupDate");
                }
            } else {
                p_req7516.dateFrom = getBankConfig().getValueAsString("hisTransSupDate");
                p_req7516.dateTo = getBankConfig().getValueAsString("hisTransSupDate");
            }
        }
        RetAtsTrans retAtsTrans = new RetAtsTrans(p_req7516.reqHeader);
        retAtsTrans.writeStart();
        String tmpRespCode = "";
        String tmpRespInfo = "";
        try {
            //起始日期
            Calendar tmpCalendarFrom = Calendar.getInstance();
            tmpCalendarFrom.setTime(p_req7516.getDateFrom());
            //结束日期
            Calendar tmpCalendarTo = Calendar.getInstance();
            tmpCalendarTo.setTime(p_req7516.getDateTo());
            //明细按月查询，有些银行不支持跨月查询
            int tmpIntDateFrom = 0;
            int tmpIntDateTo = 0;
            while (tmpIntDateFrom <= tmpIntDateTo && StringHelper.isNullOrEmpty(tmpRespCode)) {
                Calendar tmpClndrStepTo = Calendar.getInstance();
                tmpClndrStepTo.setTime(tmpCalendarFrom.getTime());
                //当是跨月查询时，先查询起始日期到月末日期记录，再查询月末后一天日期到结束日期记录
                if (DateHelper.compareMonth(tmpCalendarFrom, tmpCalendarTo) == -1) {//起始日期月份小于结束日期月份，表示跨月
                    tmpClndrStepTo.set(Calendar.DAY_OF_MONTH, tmpClndrStepTo.getActualMaximum(Calendar.DAY_OF_MONTH));//获取月末日期
                } else {
                    tmpClndrStepTo.setTime(tmpCalendarTo.getTime());
                }
                //拼接报文
                //非公有参数
                XmlTextWriter xmlTextWriter = new XmlTextWriter();
                //拼接请求报文头
                JRTT01Header header = new JRTT01Header();
                header.requestType = "account.060.001.03";//交易码
                header.msgId = getQryTransID();
                writeCommonHeader(xmlTextWriter, header);
                xmlTextWriter.writeEndElement();
                //拼接请求报文体
                xmlTextWriter.writeStartElement("ReqDetail");
                xmlTextWriter.writeElementStringWithoutTransfer("QueryType", "NTRYH");//历史明细
                xmlTextWriter.writeElementStringWithoutTransfer("BankType", p_req7516.bankType);//银行体系
                xmlTextWriter.writeElementStringWithoutTransfer("PayAccount", p_req7516.actNum);//付款帐号
                xmlTextWriter.writeElementStringWithoutTransfer("PayIBAN", p_req7516.payIBAN);//付款行iban
                xmlTextWriter.writeElementStringWithoutTransfer("FrDt", Format.Date10Format.format(tmpCalendarFrom.getTime()));//该日期为账户时区的当日日期
                xmlTextWriter.writeElementStringWithoutTransfer("ToDt", Format.Date10Format.format(tmpClndrStepTo.getTime()));//该日期为输入日期
                xmlTextWriter.writeElementStringWithoutTransfer("TimeZone", p_req7516.timeZone);//时差
                xmlTextWriter.writeEndElement();
                xmlTextWriter.writeEndDocument();
                //发送请求报文
                String[] resutlt = sendToBank(xmlTextWriter.toXmlString(), "swift");

                //WriteBankLogStep2(xmlTextWriter.toXmlString());
                //String[] resutlt=new String[]{"","<?xml version=\"1.0\" encoding=\"UTF-8\"?><Document>\t<Response>\t\t<GrpHdr>\t\t\t<ResponseType>account.060.001.03</ResponseType>\t\t\t<MsgId>20181026095026</MsgId>\t\t\t<CreDtTm>2011-01-06T17:15:00+01:00</CreDtTm>\t\t\t<OriginalMsgId>20181026095026</OriginalMsgId>\t\t\t<OriginalCreDtTm>2011-01-06T17:15:00+01:00</OriginalCreDtTm>\t\t\t<ResponseStatus>ACCP</ResponseStatus>\t\t\t<AddtlInf>错误信息</AddtlInf>\t\t</GrpHdr>\t\t<ReqDetail>\t\t\t<QueryType>NTRYH</QueryType>\t\t\t<BankType>CITI</BankType>\t\t\t<PayAccount>864691048</PayAccount>\t\t\t<PayBankSwiftCode>CITISGSG</PayBankSwiftCode>\t\t\t<FrDt>2011-01-10</FrDt>\t\t\t<ToDt>2011-01-15</ToDt>\t\t\t<TimeZone>+800</TimeZone>\t\t</ReqDetail>\t\t<Rpt>\t\t\t<Ntry>\t\t\t\t<Amt Ccy=\"USD\">582244.95</Amt>\t\t\t\t<CdtDbtInd>D</CdtDbtInd>\t\t\t\t<BookgDt>\t\t\t\t\t<DtTm>2018-01-26</DtTm>\t\t\t\t</BookgDt>\t\t\t\t<ValDt>\t\t\t\t\t<Dt>2018-01-26</Dt>\t\t\t\t</ValDt>\t\t\t\t<StsDt>\t\t\t\t\t<Dt>2018-01-26</Dt>\t\t\t\t</StsDt>\t\t\t\t<BkTxCd>\t\t\t\t\t<Prtry>\t\t\t\t\t\t<Cd>TRF</Cd>\t\t\t\t\t\t<Desc>Transfer</Desc>\t\t\t\t\t</Prtry>\t\t\t\t</BkTxCd>\t\t\t\t<NtryDtls>\t\t\t\t\t<TxDtls>\t\t\t\t\t\t<Refs>\t\t\t\t\t\t\t<InstrId>HK125018HB208930</InstrId>\t\t\t\t\t\t\t<EndToEndId>9000040000009518</EndToEndId>\t\t\t\t\t\t\t<TxId>2018012600022000010000001</TxId>\t\t\t\t\t\t</Refs>\t\t\t\t\t\t<Purp>\t\t\t\t\t\t\t<Prtry>RICHSOUND RESEARCH LTD</Prtry>\t\t\t\t\t\t</Purp>\t\t\t\t\t\t<AddtlTxInf>7404690.01</AddtlTxInf>\t\t\t\t\t</TxDtls>\t\t\t\t</NtryDtls>\t\t\t\t<AddtlNtryInf>/PT/FT/PY/CLIENT 622240001 253188 PAYMENT FOR REIMBURSEMENT/O A/IDR11500120,/OCMT/IDR11500120,/BI/7670317158/BN/TRIYANTO HIDAYA T/AB/BANK CENTRAL ASIA BCA KANTOR PUSAT OPERASIONAL/AB3/MENARA BC AFLOOR 251 JL. MH THAMRING/AB4/JAKARTA, INDONESIA/CM/USD15,00/CA/ 864691048/ER/13629,43/BO/0864691048/REF/10790IHY89B</AddtlNtryInf>\t\t\t\t<FileCreateDt>20181026013544</FileCreateDt>\t\t\t\t<IsIntraday>X</IsIntraday>\t\t\t</Ntry>\t\t\t<Ntry>\t\t\t\t<Amt Ccy=\"USD\">582244.95</Amt>\t\t\t\t<CdtDbtInd>D</CdtDbtInd>\t\t\t\t<BookgDt>\t\t\t\t\t<DtTm>2018-01-26</DtTm>\t\t\t\t</BookgDt>\t\t\t\t<ValDt>\t\t\t\t\t<Dt>2018-01-26</Dt>\t\t\t\t</ValDt>\t\t\t\t<StsDt>\t\t\t\t\t<Dt>2018-01-26</Dt>\t\t\t\t</StsDt>\t\t\t\t<BkTxCd>\t\t\t\t\t<Prtry>\t\t\t\t\t\t<Cd>TRF</Cd>\t\t\t\t\t\t<Desc>Transfer</Desc>\t\t\t\t\t</Prtry>\t\t\t\t</BkTxCd>\t\t\t\t<NtryDtls>\t\t\t\t\t<TxDtls>\t\t\t\t\t\t<Refs>\t\t\t\t\t\t\t<InstrId>HK125018HB208930</InstrId>\t\t\t\t\t\t\t<EndToEndId>9000040000009518</EndToEndId>\t\t\t\t\t\t\t<TxId>2018012600022000010000001</TxId>\t\t\t\t\t\t</Refs>\t\t\t\t\t\t<Purp>\t\t\t\t\t\t\t<Prtry>RICHSOUND RESEARCH L\n"};

                //处理响应报文
                if (resutlt[0].length() == 0) {
                    StringBuilder tmpSbMsg = new StringBuilder();
                    XmlTextReader tmpBkReader = loadBankRespXmlReader(resutlt[1].trim(), tmpSbMsg);
                    if (tmpBkReader != null) {
                        String respCode = tmpBkReader.getFirstText("/Document/Response/GrpHdr/ResponseStatus").trim();//返回码
                        String respInfo = tmpBkReader.getFirstText("/Document/Response/GrpHdr/AddtlInf");//返回信息
                        if ("ACCP".equals(respCode)) {
                            while (tmpBkReader.read("/Document/Response/Rpt/Ntry")) {
                                XElement readXElement = tmpBkReader.readedXElement;
                                RetAtsTransDetail detail = new RetAtsTransDetail();
                                detail.actArea = p_req7516.actArea;//账户区域
                                detail.actNum = p_req7516.actNum;//银行账号
                                detail.tranDate = DateHelper.convertD8toD10(readXElement.getSingleTextNotNull("BookgDt/DtTm").trim());//交易日期
                                detail.tranTime = detail.tranDate + " 00:00:00";//交易时间
                                detail.valueDate = DateHelper.convertD8toD10(readXElement.getSingleTextNotNull("ValDt/Dt").trim());//起息日
                                String payamt = readXElement.getSingleTextNotNull("Amt").trim();//交易金额
                                String cdFlag = readXElement.getSingleTextNotNull("CdtDbtInd").trim();//借贷标识
                                if ("RD".equals(cdFlag) || "C".equals(cdFlag)) {
                                    if (payamt.contains("-")) {
                                        detail.tranAmt = payamt.substring(1);
                                        detail.cdFlag = "1";
                                    } else {
                                        detail.tranAmt = payamt;
                                        detail.cdFlag = "2";
                                    }
                                } else if ("RC".equals(cdFlag) || "D".equals(cdFlag)) {
                                    if (payamt.contains("-")) {
                                        detail.tranAmt = payamt.substring(1);
                                        detail.cdFlag = "2";
                                    } else {
                                        detail.tranAmt = payamt;
                                        detail.cdFlag = "1";
                                    }
                                }
                                detail.accBal = readXElement.getSingleTextNotNull("NtryDtls/TxDtls/AddtlTxInf").trim();//账户余额                                detail.abstr = "";//对账码
                                detail.busType = readXElement.getSingleTextNotNull("BkTxCd/Prtry/Desc");//摘要
                                detail.abstr = "";//对账码
                                detail.cur = convertCurToATS(readXElement.getSingleChild("Amt").getAttrValue("Ccy"));//币种
                                detail.askNumber = readXElement.getSingleTextNotNull("NtryDtls/TxDtls/Refs/EndToEndId").trim();
                                detail.originator = detail.askNumber;
                                detail.comment = readXElement.getSingleTextNotNull("AddtlNtryInf");
//                                detail.payCode = readXElement.getSingleTextNotNull("NtryDtls/TxDtls/Purp/Prtry");
                                String inTransDate = getBankConfig().getSetValue("inTransDate", "", p_req7516.reqHeader.transType);
                                if (com.fingard.text.StringHelper.hasAnyChar(inTransDate) && inTransDate.length() == 8) {
                                    //判断起始日
                                    Date avaiDate = Format.Date8Format.parse(inTransDate);//生效时间
                                    Date tranDate = Format.Date8Format.parse(DateHelper.convertD10toD8(detail.tranDate));//交易时间
                                    if (!tranDate.before(avaiDate)) {
                                        //生效，增加节点
                                        detail.uniqueID = p_req7516.actNum + "-" + readXElement.getSingleTextNotNull("NtryDtls/TxDtls/Refs/TxId");//防重标识
                                    }
                                }
                                Map<String, String> map = new HashMap<String, String>();
                                //解析86字段
                                if ("1".equals(getBankConfig().getValueAsString("tag86PlayFlag"))) {
                                    map = resolveTag86(detail.comment, detail.cdFlag, true);
                                } else if (StringHelper.hasAnyChar(readXElement.getSingleTextNotNull("AddtlNtryInfDetail"))) {
                                    map = resolveTag86(readXElement.getSingleTextNotNull("AddtlNtryInfDetail"));
                                }
                                if (map.size() > 0) {
                                    detail.recAccNum = StringHelper.isNullOrEmpty(map.get("RecAccNum")) ? "" : map.get("RecAccNum");//收方银行账号
                                    detail.recAccName = StringHelper.isNullOrEmpty(map.get("RecAccName")) ? "" : map.get("RecAccName");//收方账户名称
                                    detail.recAccBank = StringHelper.isNullOrEmpty(map.get("RecAccBannk")) ? "" : map.get("RecAccBannk");//收方银行名称
                                    detail.usage = StringHelper.isNullOrEmpty(map.get("Usage")) ? "" : map.get("Usage");//用途
                                    detail.originator = StringHelper.isNullOrEmpty(map.get("Originator")) ? "" : map.get("Originator");
                                    detail.payCode = StringHelper.isNullOrEmpty(map.get("opIdentifyCode")) ? "" : map.get("opIdentifyCode");
                                }

                                retAtsTrans.writeRetDetail(detail);
                            }
                        } else {//查询异常
                            tmpRespCode = "-1";
                            tmpRespInfo = respInfo;
                            break;
                        }
                    } else {
                        tmpRespCode = "-1";
                        tmpRespInfo = tmpSbMsg.toString();
                        break;
                    }
                } else {
                    tmpRespCode = "-1";
                    tmpRespInfo = resutlt[1];
                    break;
                }
                tmpCalendarFrom = tmpClndrStepTo;
                tmpCalendarFrom.add(Calendar.DAY_OF_MONTH, 1);//月末后一天日期
                tmpIntDateFrom = Integer.parseInt(Format.Date8Format.format(tmpCalendarFrom.getTime()));
                tmpIntDateTo = Integer.parseInt(Format.Date8Format.format(tmpCalendarTo.getTime()));
            }
        } catch (Exception ex) {
            tmpRespCode = "-1";
            tmpRespInfo = ex.getMessage();
            ex.printStackTrace();
            WriteBankLogLn("查询明细异常:" + ex);
        }
        if ("-1".equals(tmpRespCode)) {
            retAtsTrans = new RetAtsTrans(p_req7516.reqHeader);
            retAtsTrans.writeStart();//写返回ATS的统一头部信息
            retAtsTrans.writeRespCode(tmpRespCode);
            retAtsTrans.writeRespInfo(tmpRespInfo);
        } else if (retAtsTrans.getWrittenRdCount() == 0) {
            retAtsTrans.writeRespInfo("交易为空");
            retAtsTrans.writeRespCode("0");
        }
        retAtsTrans.writeEnd();
        return retAtsTrans;
    }

    /**
     * 今日明细
     *
     * @param p_req7515
     * @return
     * @throws Exception
     */
    @Override
    public RetAtsTrans d_7515_TodayTrans(Req7515TodayTrans p_req7515) throws Exception {
        RetAtsTrans retAtsTrans = new RetAtsTrans(p_req7515.reqHeader);
        retAtsTrans.writeStart();
        String tmpRespCode = "";
        String tmpRespInfo = "";
        try {
            //查询时间日期
            Calendar tmpCalendarFrom = Calendar.getInstance();
            tmpCalendarFrom.setTime(Format.DateTimeFormat.parse(Format.DateTimeFormat.format(new Date())));
            //拼接报文
            //非公有参数
            XmlTextWriter xmlTextWriter = new XmlTextWriter();
            //拼接请求报文头
            JRTT01Header header = new JRTT01Header();
            header.requestType = "account.060.001.03";//交易码
            header.msgId = getQryTransID();
            writeCommonHeader(xmlTextWriter, header);
            xmlTextWriter.writeEndElement();
            //拼接请求报文体
            xmlTextWriter.writeStartElement("ReqDetail");
            xmlTextWriter.writeElementStringWithoutTransfer("QueryType", "NTRYI");//今日明细
            xmlTextWriter.writeElementStringWithoutTransfer("BankType", p_req7515.bankType);//银行体系
            xmlTextWriter.writeElementStringWithoutTransfer("PayAccount", p_req7515.actNum);//付款帐号
            xmlTextWriter.writeElementStringWithoutTransfer("PayIBAN", p_req7515.payIBAN);//付款行SwiftCode
            xmlTextWriter.writeElementStringWithoutTransfer("FrDt", getGlobalLocalDate(tmpCalendarFrom.getTime(), p_req7515.timeZone));//该日期为账户时区的当日日期
            xmlTextWriter.writeElementStringWithoutTransfer("ToDt", Format.Date10Format.format(tmpCalendarFrom.getTime()));//该日期为输入日期
            xmlTextWriter.writeElementStringWithoutTransfer("TimeZone", p_req7515.timeZone);//时差
            xmlTextWriter.writeEndElement();
            xmlTextWriter.writeEndDocument();
            //发送请求报文
            String[] resutlt = sendToBank(xmlTextWriter.toXmlString(), "swift");
            //处理响应报文
            if (resutlt[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(resutlt[1].trim(), tmpSbMsg);
                if (tmpBkReader != null) {
                    String respCode = tmpBkReader.getFirstText("/Document/Response/GrpHdr/ResponseStatus").trim();//返回码
                    String respInfo = tmpBkReader.getFirstText("/Document/Response/GrpHdr/AddtlInf");//返回信息
                    if ("ACCP".equals(respCode)) {
                        while (tmpBkReader.read("/Document/Response/Rpt/Ntry")) {
                            XElement readXElement = tmpBkReader.readedXElement;
                            RetAtsTransDetail detail = new RetAtsTransDetail();
                            detail.actArea = p_req7515.actArea;//账户区域
                            detail.actNum = p_req7515.actNum;//银行账号
                            detail.tranDate = DateHelper.convertD8toD10(readXElement.getSingleTextNotNull("BookgDt/DtTm").trim());//交易日期
                            detail.tranTime = detail.tranDate + " 00:00:00";//交易时间
                            detail.valueDate = DateHelper.convertD8toD10(readXElement.getSingleTextNotNull("ValDt/Dt").trim());//起息日
                            String payamt = readXElement.getSingleTextNotNull("Amt").trim();//交易金额
                            String cdFlag = readXElement.getSingleTextNotNull("CdtDbtInd").trim();//借贷标识
                            if ("RD".equals(cdFlag) || "C".equals(cdFlag)) {
                                if (payamt.contains("-")) {
                                    detail.tranAmt = payamt.substring(1);
                                    detail.cdFlag = "1";
                                } else {
                                    detail.tranAmt = payamt;
                                    detail.cdFlag = "2";
                                }
                            } else if ("RC".equals(cdFlag) || "D".equals(cdFlag)) {
                                if (payamt.contains("-")) {
                                    detail.tranAmt = payamt.substring(1);
                                    detail.cdFlag = "2";
                                } else {
                                    detail.tranAmt = payamt;
                                    detail.cdFlag = "1";
                                }
                            }
                            detail.accBal = readXElement.getSingleTextNotNull("NtryDtls/TxDtls/AddtlTxInf").trim();//账户余额
                            detail.busType = readXElement.getSingleTextNotNull("BkTxCd/Prtry/Desc");//摘要
                            detail.abstr = "";//对账码
                            detail.cur = convertCurToATS(readXElement.getSingleChild("Amt").getAttrValue("Ccy"));//币种
                            detail.comment = readXElement.getSingleTextNotNull("AddtlNtryInf");
                            detail.askNumber = readXElement.getSingleTextNotNull("NtryDtls/TxDtls/Refs/EndToEndId").trim();
                            detail.originator = detail.askNumber;
//                            detail.payCode = readXElement.getSingleTextNotNull("NtryDtls/TxDtls/Purp/Prtry");
                            String inTransDate = getBankConfig().getSetValue("inTransDate", "", p_req7515.reqHeader.transType);
                            if (com.fingard.text.StringHelper.hasAnyChar(inTransDate) && inTransDate.length() == 8) {
                                //判断起始日
                                Date avaiDate = Format.Date8Format.parse(inTransDate);//生效时间
                                Date tranDate = Format.Date8Format.parse(DateHelper.convertD10toD8(detail.tranDate));//交易时间
                                if (!tranDate.before(avaiDate)) {
                                    //生效，增加节点
                                    detail.uniqueID = p_req7515.actNum + "-" + readXElement.getSingleTextNotNull("NtryDtls/TxDtls/Refs/TxId");//防重标识
                                }
                            }
                            Map<String, String> map = new HashMap<String, String>();
                            //解析86字段
                            if ("1".equals(getBankConfig().getValueAsString("tag86PlayFlag"))) {
                                map = resolveTag86(detail.comment, detail.cdFlag, false);
                            } else if (StringHelper.hasAnyChar(readXElement.getSingleTextNotNull("AddtlNtryInfDetail"))) {
                                map = resolveTag86(readXElement.getSingleTextNotNull("AddtlNtryInfDetail"));
                            }
                            if (map.size() > 0) {
                                detail.recAccNum = StringHelper.isNullOrEmpty(map.get("RecAccNum")) ? "" : map.get("RecAccNum");//收方银行账号
                                detail.recAccName = StringHelper.isNullOrEmpty(map.get("RecAccName")) ? "" : map.get("RecAccName");//收方账户名称
                                detail.recAccBank = StringHelper.isNullOrEmpty(map.get("RecAccBannk")) ? "" : map.get("RecAccBannk");//收方银行名称
                                detail.usage = StringHelper.isNullOrEmpty(map.get("Usage")) ? "" : map.get("Usage");//用途
                                detail.originator = StringHelper.isNullOrEmpty(map.get("Originator")) ? "" : map.get("Originator");
                                detail.payCode = StringHelper.isNullOrEmpty(map.get("opIdentifyCode")) ? "" : map.get("opIdentifyCode");
                            }

                            retAtsTrans.writeRetDetail(detail);
                        }
                    } else {//查询异常
                        tmpRespCode = "-1";
                        tmpRespInfo = respInfo;
                    }
                } else {
                    tmpRespCode = "-1";
                    tmpRespInfo = tmpSbMsg.toString();
                }
            } else {
                tmpRespCode = "-1";
                tmpRespInfo = resutlt[1];
            }
        } catch (Exception ex) {
            tmpRespCode = "-1";
            tmpRespInfo = ex.getMessage();
            ex.printStackTrace();
            WriteBankLogLn("查询明细异常:" + ex);
        }
        if ("-1".equals(tmpRespCode)) {
            retAtsTrans = new RetAtsTrans(p_req7515.reqHeader);
            retAtsTrans.writeStart();//写返回ATS的统一头部信息
            retAtsTrans.writeRespCode(tmpRespCode);
            retAtsTrans.writeRespInfo(tmpRespInfo);
        } else if (retAtsTrans.getWrittenRdCount() == 0) {
            retAtsTrans.writeRespCode("0");
            retAtsTrans.writeRespInfo("交易为空");
        }
        retAtsTrans.writeEnd();
        return retAtsTrans;
    }
}
